//
//  AppInfo.swift
//  Inquiry
//
//  Created by SSD on 2019/9/3.
//  Copyright © 2019 SSD. All rights reserved.
//

import Foundation
import SWApplicationEnvironment
import SWLog
import SWCommonExtensions
class AppInfo {
    static let `default` = AppInfo()
    
    fileprivate(set) var displayName: String = ""
    fileprivate(set) var identifier: String = ""
    fileprivate(set) var version: String = ""
    fileprivate(set) var build: String = ""
}

extension AppInfo {
    func onLaunching() {
        
        if environment != .distribution {
            SWLog.log("[LAUNCH]\nAppInfo onLaunching...")
        }
        
        guard let infoDict = Bundle.main.infoDictionary else { return }
        
        if let displayName = infoDict.string(for: "CFBundleDisplayName") {
            self.displayName = displayName
        }else if let name = infoDict.string(for: "CFBundleName"){
            self.displayName = name
        }
        if let identifier = infoDict.string(for: "CFBundleIdentifier") {
            self.identifier = identifier
        }
        if let version = infoDict.string(for: "CFBundleShortVersionString") {
            self.version = version
        }
        if let build = infoDict.string(for: "CFBundleVersion") {
            self.build = build
        }
        
        if environment != .distribution {
            SWLog.log("[LAUNCH]\nAppInfo has launched.")
        }
    }
}
extension AppInfo: SWEnvironmentProtocal {
    var environment: ApplicationEnvironment {
        return .development
    }
    
    var projectEnvironment: ProjectEnvironment {
        return .debug
    }
    
    var channel: ProjectChannel {
        return .debug
    }
}


